package com.lxh.lxhcrm.controller.presale;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.lxh.lxhcrm.model.pojos.ActionRecord;
import com.lxh.lxhcrm.model.pojos.ActionType;
import com.lxh.lxhcrm.model.pojos.Behavior;
import com.lxh.lxhcrm.model.pojos.BehaviorRecord;
import com.lxh.lxhcrm.model.service.ActRecordService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 开发团队 ：lxh
 * 开发人员 ：罗晓
 * 开发时间 ：2020/2/29 10:34
 * 类的名称 ：ActRecordController
 * 类的描述 ：售前模块员工行动记录controller，进行前后端的数据传输控制
 * @author 罗晓
 */
@RestController
@RequestMapping("/actrecord")
public class ActRecordController {
    @Resource
    ActRecordService as;

    /**
     * 带分页的员工对客户行动记录查询
     * @param currPage
     * @param pageSize
     * @return Map<Integer,Object>
     */
    @RequestMapping("/act")
    public Map<String,Object> findActRecord(Integer currPage, Integer pageSize, Integer type, String search, Integer value, Date startDate, Date endDate){
        if (currPage == null || currPage == 0){ currPage = 1;}
        if (pageSize == null || pageSize == 0){ pageSize = 8;}
        /* 分页 */
        Page<Object> page = PageHelper.startPage(currPage, pageSize);
        Map<String,Object> actR = new HashMap<>();
        List<ActionRecord> list = as.findAllActRecord(type,search,value,startDate,endDate);
        actR.put("data",list);
        actR.put("total",page.getTotal());
        return actR;
    }

    /**
     * 不带分页的查询行动记录
     * @return List<ActionRecord>
     */
    @RequestMapping("/actNoPage")
    public List<ActionRecord> findActRecord(Integer type,String search, Integer value, Date startDate, Date endDate){
        List<ActionRecord> list = as.findAllActRecord(type,search,value,startDate,endDate);
        return list;
    }

    /**
     * 获取行动类别
     * @return
     */
    @RequestMapping("/getactType")
    public List<ActionType> getactType(){
        List<ActionType> list = as.getactType();
        return list;
    }
    /**
     * 获取客户行为类别
     * @return
     */
    @RequestMapping("/getBehaviorType")
    public List<Behavior> getBehaviorType(){
        List<Behavior> list = as.getBehaviorType();
        return list;
    }
    /**
     * 添加和修改
     * @param moveBehavior
     */
    @PostMapping("/saveactRecort")
    public void addActRecord(@RequestBody ActionRecord moveBehavior){
        System.out.println(moveBehavior);
        as.addActRecord(moveBehavior);
    }

    /**
     *后台通过customerId查出记录
     * @param customerId
     * @return
     */
    @RequestMapping("/allrecord")
    public List<ActionRecord> findActBeRecord(Integer customerId){
        return as.findActBeRecord(customerId);
    }

    @PostMapping("/saveBehavior")
    public void addbehavior(@RequestBody BehaviorRecord behaviorRecord){
        System.out.println(behaviorRecord);
        as.addbehavior(behaviorRecord);
    }

    /**
     * 点赞功能
     * @param empId
     * @param actionRecordId
     */
    @RequestMapping("/giveLike")
    public void giveLike(Integer empId,Integer actionRecordId){
        as.giveLike(empId,actionRecordId);
    }

    @RequestMapping("/deleteAction")
    public void deleteAction(Integer actionRecordId){as.deleteAction(actionRecordId);}
}
